package orders

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"order_srv/orderclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type InvoicePDFLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInvoicePDFLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InvoicePDFLogic {
	return &InvoicePDFLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 生成发票
func (l *InvoicePDFLogic) InvoicePDF(req *types.InvoicePDFRequest) (resp *types.Response, err error) {
	//业务逻辑
	invoicePdf, err := l.svcCtx.OrderRpc.InvoicePDF(l.ctx, &orderclient.InvoicePDFRequest{
		InvoiceId: req.InvoiceId,
	})

	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}
	return respons.Success(invoicePdf), nil
}
